<?php
declare (strict_types=1);

namespace app\exam\model\admin;

use app\common\model\BaseModel;
use app\user\model\user\admin\Account;

/**
 * Class PaperAnswerRecord
 *
 * @package app\exam\model\admin
 */
class PaperAnswerRecord extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'exam_paper_answer_record';

    /**
     * 定义字段类型
     *
     * @var [type]
     */
    protected $type = [
        'user_id'     => 'intger',
        'paper_id'    => 'intger',
        'paper_parts' => 'json',
        'answer_data' => 'json',
        'commit_time' => 'timestamp'
    ];

    /**
     * 时间显示格式
     *
     * @var string
     */
    protected $dateFormat = 'Y-m-d H:i';

    /**
     * 试卷名称
     */
    public function paperInfo()
    {
        return $this
            ->belongsTo(Paper::class, 'paper_id')
            ->bind(['paper_title' => 'title', 'paper_type'])
            ->removeOption('soft_delete')
            ->removeWhereField('mhm_id');
    }

    /**
     * 关联用户
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-30
     *
     * @return   [type]                         [description]
     */
    public function user()
    {
        return $this
            ->belongsTo(Account::class, 'user_id')
            ->with(['avatar_url'])
            ->removeOption('soft_delete')
            ->removeWhereField('mhm_id');
    }

}